package com.ym.jiujiangeyou.adapter;

import java.util.List;

import com.ym.jiujiangeyou.R;
import com.ym.jiujiangeyou.bitmap.ImageLoader;

import android.content.Context;
import com.ym.jiujiangeyou.entity.Scenery;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
 /**   
 * @author 叶铭   
 * @email yeming_1001@163.com
 * @version V1.0   
 * @Description: 景点列表适配器
 */
public class SceneryListAdapter extends BaseAdapter {

	private LayoutInflater inflater ;
	private Context context ;
	private ImageLoader loader ;
	private List<Scenery> list ;
	
	public SceneryListAdapter(Context context) {
		this.context = context ;
		this.inflater = LayoutInflater.from(context) ;
		loader = new ImageLoader(context) ;
	//	loader.setDefaultBitmap(context.getResources().getDrawable(R.drawable.ic_empty)) ;
	}
	
	public void setData(List<Scenery> list){
		this.list = list ;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size() ;
		
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position) ;
		
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position ;
		
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder viewHolder ;
	//	View view ;
		if(convertView == null){
			viewHolder = new ViewHolder() ;
			convertView = inflater.inflate(R.layout.scenery_list_item, null) ;
			viewHolder.imageView = (ImageView) convertView.findViewById(R.id.iv_image) ;
			viewHolder.textView1 = (TextView) convertView.findViewById(R.id.tv_name) ;
			viewHolder.textView2 = (TextView) convertView.findViewById(R.id.tv_address) ;
			viewHolder.textView3 = (TextView) convertView.findViewById(R.id.tv_ticket) ;
			viewHolder.textView4 = (TextView) convertView.findViewById(R.id.tv_type) ;
			convertView.setTag(viewHolder) ;
		}else{
			viewHolder = (ViewHolder) convertView.getTag() ;
		}
		viewHolder.textView1.setText(list.get(position).getName().toString()) ;
		viewHolder.textView2.setText(list.get(position).getAddress().toString()) ;
		viewHolder.textView3.setText(list.get(position).getTicket().toString()) ;
	//	viewHolder.textView3.setText("168元") ;
		viewHolder.textView4.setText(list.get(position).getType().toString()) ;
		//imageLoad.loadImage(list.get(position).getImageurl().toString(), viewHolder.imageView) ;
	//	imageLoad.loadImage("http://imgt7.bdstatic.com/it/u=2,885694682&fm=19&gp=0.jpg", viewHolder.imageView) ;
	//	viewHolder.imageView.setBackgroundResource(R.drawable.sd) ;
		loader.DisplayImage(list.get(position).getImageurl().toString(), viewHolder.imageView, false) ;
		return convertView ;
		
	}
	
	class ViewHolder{
		ImageView imageView ;
		TextView textView1,textView2,textView3,textView4 ;
	}

}
